<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>成语学习助手</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 30px 20px;
            color: #333;
        }
        
        .container {
            width: 100%;
            max-width: 800px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            overflow: hidden;
            padding: 30px;
        }
        
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 5px;
            font-size: 2.5rem;
            background: linear-gradient(90deg, #3498db, #8e44ad);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .subtitle {
            text-align: center;
            color: #7f8c8d;
            margin-bottom: 30px;
            font-size: 1.1rem;
        }
        
        .upload-section {
            background: #f8f9fa;
            border: 2px dashed #3498db;
            border-radius: 12px;
            padding: 30px;
            text-align: center;
            margin-bottom: 30px;
            transition: all 0.3s ease;
        }
        
        .upload-section:hover {
            background: #e3f2fd;
            transform: translateY(-3px);
        }
        
        .upload-section p {
            margin-bottom: 20px;
            color: #555;
            font-size: 1.1rem;
        }
        
        .file-input-wrapper {
            position: relative;
            display: inline-block;
            overflow: hidden;
            margin-bottom: 15px;
        }
        
        .file-input-wrapper input[type="file"] {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            cursor: pointer;
            width: 100%;
            height: 100%;
        }
        
        .file-input-button {
            display: inline-block;
            padding: 12px 30px;
            background: #3498db;
            color: white;
            border-radius: 50px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
        }
        
        .file-input-button:hover {
            background: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(52, 152, 219, 0.4);
        }
        
        .sample-file {
            font-size: 0.9rem;
            color: #7f8c8d;
        }
        
        .learning-section {
            display: none;
            text-align: center;
        }
        
        .idiom-display {
            font-size: 2.8rem;
            font-weight: 700;
            margin: 40px 0;
            color: #2c3e50;
            min-height: 120px;
            display: flex;
            align-items: center;
            justify-content: center;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .explanation-display {
            font-size: 1.4rem;
            color: #34495e;
            line-height: 1.8;
            padding: 25px;
            margin: 30px 0;
            background: #f8f9fa;
            border-radius: 12px;
            box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
            min-height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.5s ease;
        }
        
        .explanation-display.show {
            opacity: 1;
            transform: translateY(0);
        }
        
        .action-button {
            padding: 15px 50px;
            font-size: 1.2rem;
            background: #9b59b6;
            color: white;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: 600;
            margin: 20px auto;
            display: block;
            box-shadow: 0 4px 15px rgba(155, 89, 182, 0.4);
        }
        
        .action-button:hover {
            background: #8e44ad;
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(155, 89, 182, 0.5);
        }
        
        .action-button:active {
            transform: translateY(1px);
        }
        
        .progress-container {
            margin-top: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 12px;
        }
        
        .progress-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
            font-size: 1.1rem;
            color: #7f8c8d;
        }
        
        .progress-bar {
            height: 16px;
            background: #ecf0f1;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #3498db, #1abc9c);
            border-radius: 8px;
            width: 0%;
            transition: width 0.5s ease;
        }
        
        .progress-text {
            text-align: center;
            margin-top: 15px;
            font-size: 1.1rem;
            color: #34495e;
        }
        
        .instructions {
            margin-top: 30px;
            padding: 20px;
            background: #e8f4fc;
            border-radius: 12px;
            border-left: 4px solid #3498db;
        }
        
        .instructions h3 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        
        .instructions ul {
            padding-left: 20px;
        }
        
        .instructions li {
            margin-bottom: 8px;
            line-height: 1.5;
        }
        
        .footer {
            margin-top: 30px;
            text-align: center;
            color: #7f8c8d;
            font-size: 0.9rem;
        }
        
        @media (max-width: 600px) {
            .container {
                padding: 20px 15px;
            }
            
            h1 {
                font-size: 2rem;
            }
            
            .idiom-display {
                font-size: 2.2rem;
                min-height: 100px;
            }
            
            .explanation-display {
                font-size: 1.2rem;
                padding: 15px;
            }
            
            .action-button {
                padding: 12px 40px;
                font-size: 1.1rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>成语学习助手</h1>
        <p class="subtitle">上传成语文件，随机学习成语，提高语言能力</p>
        
        <div class="upload-section" id="upload-section">
            <p>请上传包含成语的Markdown文件</p>
            <div class="file-input-wrapper">
                <input type="file" id="file-input" accept=".md">
                <div class="file-input-button">选择文件</div>
            </div>
            <p class="sample-file">示例文件格式：1. 成语：解释</p>
        </div>
        
        <div class="learning-section" id="learning-section">
            <div class="idiom-display" id="idiom-display"></div>
            <div class="explanation-display" id="explanation-display"></div>
            <button class="action-button" id="action-button">显示解释</button>
            
            <div class="progress-container">
                <div class="progress-header">
                    <span>学习进度</span>
                    <span id="progress-text">0/0</span>
                </div>
                <div class="progress-bar">
                    <div class="progress-fill" id="progress-fill"></div>
                </div>
                <div class="progress-text" id="status-text">准备开始学习</div>
            </div>
        </div>
        
        <div class="instructions">
            <h3>使用说明：</h3>
            <ul>
                <li>1. 上传包含成语的Markdown文件（格式：序号. 成语：解释）</li>
                <li>2. 系统会随机展示一个成语，但隐藏解释</li>
                <li>3. 点击"显示解释"按钮查看成语含义</li>
                <li>4. 再次点击按钮切换到下一个成语</li>
                <li>5. 进度条显示学习进度，确保每个成语只学习一次</li>
            </ul>
        </div>
        
        <div class="footer">
            <p>© 2023 成语学习助手 | 提升语言能力，传承中华文化</p>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const fileInput = document.getElementById('file-input');
            const uploadSection = document.getElementById('upload-section');
            const learningSection = document.getElementById('learning-section');
            const idiomDisplay = document.getElementById('idiom-display');
            const explanationDisplay = document.getElementById('explanation-display');
            const actionButton = document.getElementById('action-button');
            const progressFill = document.getElementById('progress-fill');
            const progressText = document.getElementById('progress-text');
            const statusText = document.getElementById('status-text');
            
            let idioms = [];
            let learnedIdioms = [];
            let currentIdiom = null;
            
            // 处理文件上传
            fileInput.addEventListener('change', function(e) {
                const file = e.target.files[0];
                if (!file) return;
                
                const reader = new FileReader();
                reader.onload = function(event) {
                    const content = event.target.result;
                    parseIdioms(content);
                    
                    if (idioms.length > 0) {
                        uploadSection.style.display = 'none';
                        learningSection.style.display = 'block';
                        nextIdiom();
                        updateProgress();
                    } else {
                        alert('未找到有效的成语数据，请检查文件格式！');
                    }
                };
                reader.readAsText(file);
            });
            
            // 解析成语数据
            function parseIdioms(content) {
                idioms = [];
                const lines = content.split('\n');
                
                // 使用正则表达式匹配成语格式：1. 成语：解释
                const idiomRegex = /^\d+\.\s+(.+?)[：:]\s*(.+)$/;
                
                for (const line of lines) {
                    const trimmedLine = line.trim();
                    if (!trimmedLine) continue;
                    
                    const match = trimmedLine.match(idiomRegex);
                    if (match) {
                        const idiom = match[1].trim();
                        const explanation = match[2].trim();
                        idioms.push({ idiom, explanation });
                    }
                }
            }
            
            // 获取下一个随机成语
            function nextIdiom() {
                if (idioms.length === 0) return;
                
                // 从未学习的成语中随机选择一个
                const unlearned = idioms.filter(item => !learnedIdioms.includes(item.idiom));
                
                if (unlearned.length === 0) {
                    // 所有成语都学完了
                    idiomDisplay.textContent = '恭喜！已完成所有成语学习';
                    explanationDisplay.textContent = '';
                    explanationDisplay.classList.remove('show');
                    actionButton.textContent = '重新开始';
                    actionButton.onclick = resetLearning;
                    return;
                }
                
                const randomIndex = Math.floor(Math.random() * unlearned.length);
                currentIdiom = unlearned[randomIndex];
                
                idiomDisplay.textContent = currentIdiom.idiom;
                explanationDisplay.textContent = currentIdiom.explanation;
                explanationDisplay.classList.remove('show');
                actionButton.textContent = '显示解释';
                actionButton.onclick = showExplanation;
            }
            
            // 显示当前成语的解释
            function showExplanation() {
                explanationDisplay.classList.add('show');
                actionButton.textContent = '下一个成语';
                actionButton.onclick = nextWithLearning;
                
                // 添加到已学习列表
                if (currentIdiom && !learnedIdioms.includes(currentIdiom.idiom)) {
                    learnedIdioms.push(currentIdiom.idiom);
                }
            }
            
            // 学习下一个成语
            function nextWithLearning() {
                nextIdiom();
                updateProgress();
            }
            
            // 更新进度条
            function updateProgress() {
                const total = idioms.length;
                const learned = learnedIdioms.length;
                const progress = total > 0 ? Math.round((learned / total) * 100) : 0;
                
                progressFill.style.width = `${progress}%`;
                progressText.textContent = `${learned}/${total}`;
                
                if (total === 0) {
                    statusText.textContent = '准备开始学习';
                } else if (learned === total) {
                    statusText.textContent = '恭喜！你已完成所有成语学习';
                } else {
                    statusText.textContent = `已学习 ${learned} 个成语，剩余 ${total - learned} 个`;
                }
            }
            
            // 重置学习
            function resetLearning() {
                learnedIdioms = [];
                nextIdiom();
                updateProgress();
            }
            
            // 初始化示例数据（用于演示）
            function initSampleData() {
                idioms = [
                    { idiom: "踌躇满志", explanation: "形容对自己取得的成就非常得意" },
                    { idiom: "正本清源", explanation: "从根源上进行改革" },
                    { idiom: "一板一眼", explanation: "比喻行为有条理，合规矩，不马虎" },
                    { idiom: "一蹴而就", explanation: "踏一步就成功。形容事情轻而易举，一下子就能完成" },
                    { idiom: "有的放矢", explanation: "对准靶子射箭。比喻言论、行动目标明确" }
                ];
                
                uploadSection.style.display = 'none';
                learningSection.style.display = 'block';
                nextIdiom();
                updateProgress();
            }
            
            // 初始化时加载示例数据（用于演示）
            // 在实际使用中应注释掉这行
            // initSampleData();
        });
    </script>
</body>
</html>